Test Series - Data Structure

Test Number 32/115

Q: What is the time complexity of balancing parentheses algorithm?
A. O (N)
B. O (N log N)
C. O (M log N)
D. O (N2)
Solution: The time complexity of balancing parentheses algorithm is mathematically found to be O (N).
Q: Which application of stack is used to ensure that the pair of parentheses is properly nested?
A. Balancing symbols
B. Reversing a stack
C. Conversion of an infix to postfix expression
D. Conversion of an infix to prefix expression
Solution: Balancing symbols application ensures that the pair of parentheses are properly nested while reversing stack reverses a stack.
Q: In balancing parentheses algorithm, the string is read from?
A. right to left
B. left to right
C. center to right
D. center to left
Solution: Any string is read by the compiler from left to right and not from right to left.
Q: Which is the most appropriate data structure for applying balancing of symbols algorithm?
A.  stack
B. queue
C. tree
D. graph
Solution: Stack is the most appropriate data structure for balancing symbols algorithm because stack follows LIFO principle (Last In First Out).
Q: Which of the following does the balancing symbols algorithm include?
A. balancing double quotes
B. balancing single quotes
C. balancing operators and brackets
D. balancing parentheses, brackets and braces
Solution: The balancing symbols algorithm using stack only includes balancing parentheses, brackets and braces and not any other symbols.
Q: Which of the following statement is incorrect with respect to balancing symbols algorithm?
A. {[()]}
B. ([ )]
C. {( )}
D. { [ ] }
Solution: ([ )] is incorrect because’)’ occurs before the corresponding ‘]’ is encountered.
Q: What should be done when an opening parentheses is read in a balancing symbols algorithm?
A. push it on to the stack
B.  throw an error
C. ignore the parentheses
D. pop the stack
Solution: When an opening bracket/braces/parentheses is encountered, it is pushed on to the stack. When the corresponding end bracket/braces/parentheses is not found, throw an error.
Q: When the corresponding end bracket/braces/parentheses is not found, what happens?
A. The stack is popped
B. Ignore the parentheses
C. An error is reported
D. It is treated as an exception
Solution: When the corresponding end bracket/braces/parentheses is not found, throw an error since they don’t match.
Q: If the corresponding end bracket/braces/parentheses is encountered, which of the following is done?
A. push it on to the stack
B. pop the stack
C. throw an error
D. treated as an exception
Solution: When the corresponding end bracket/braces/parentheses is encountered, the stack is popped. When an opening bracket/braces/parentheses is encountered, it is pushed on to the stack.
Q: Which of the following statement is invalid with respect to balancing symbols?
A. [(A+B) + (C-D)]
B. [{A+B}-{C-[D+E]}]
C. ((A+B) + (C+D)
D. {(A+B) + [C+D]}
Solution: ((A+B) + (C+D) is invalid because the last close brace is not found in the statement.

You Have Score    /10